#ifndef __BTL_FINGERPRINT_API_H__
#define __BTL_FINGERPRINT_API_H__
#include "btl_config.h"

#define TASK_VERIFY_LED   0
#define TASK_ENROLL_LED   1
#define TASK_REMOVE_LED   2
#define TASK_EXITVIP_LED  3 /* 退出管理员模式 */
#define TASK_RECOVERY_LED 4 /* 进入恢复模式 */
#define TASK_RESET_LED    5 /* 清除灯状态 */

#define MEASURE_PHASE0  0
#define MEASURE_PHASE1  1
#define MEASURE_PHASE2  2
#define MEASURE_PHASE3  3
#define MEASURE_PHASE4  4
#define MEASURE_PHASE5  5
#define MEASURE_PHASE6  6
#define MEASURE_PHASE7  7
#define MEASURE_PHASE8  8
#define MEASURE_PHASE9  9
#define MEASURE_PHASE10 10

#define TASK_VERIFY_COMPLETED_LED   00 /* 比对结果 */
#define TASK_ENROLL_TODO_LED        10 /* 进入录入模式 */
#define TASK_ENROLL_ADDED_LED       11 /* 录入过程中 */
#define TASK_ENROLL_COMPLETED_LED   12 /* 录入完成时 */
#define TASK_REMOVE_TODO_LED        20 /* 进入删除模式 */
#define TASK_REMOVE_COMPLETED_LED   21 /* 进入删除模式 */
#define TASK_RECOVERY_TODO_LED      30 /* 进入恢复模式 */
#define TASK_RECOVERY_CHECK_LED     31 /* 校验恢复模式 */
#define TASK_RECOVERY_COMPLETED_LED 32 /* 完成恢复模式 */
#define TASK_RECOVERY_INPUT_LED     33 /* 恢复模式输入灯效 */
#define TASK_RECOVERY_TO_STAGE2     34 /* 切换到恢复模式第2阶段 */

#ifdef __HZ_PROJECT__
#define FP_ENROLL_TIMEOUT   5 * 1000  /* 8s */
#define FP_REMOVE_TIMEOUT   10 * 1000 /* 15s */
#define FP_MANAGER_TIMEOUT  20 * 1000 /* 25s */
#define FP_RECOVERY_TIMEOUT 60 * 1000 /* 60s */
#else
#define FP_ENROLL_TIMEOUT   8 * 1000  /* 8s */
#define FP_REMOVE_TIMEOUT   15 * 1000 /* 15s */
#define FP_MANAGER_TIMEOUT  25 * 1000 /* 25s */
#define FP_RECOVERY_TIMEOUT 60 * 1000 /* 60s */
#endif

#define LIGHTON_TODO_ENROLL   1
#define LIGHTON_TODO_REMOVE   2
#define LIGHTON_TODO_RECOVERY 3
#define LIGHTON_TODO_EXIT     4

#define RECOVERY_ID1         6
#define RECOVERY_ID2         3
#define RECOVERY_ID_DIFFTIME 3 * 1000 /* 3s */
#define RECOVERY_TIMEOUT     5 * 1000 /* 5s */

struct fp_protocol_info {
    unsigned int mode;           /* 开启指纹管理侦测模式 */
    unsigned int task;           /* 添加/删除指纹 */
    unsigned int fingerdown;     /* 是否有手指按压: 1 */
    unsigned int identify_valid; /* 比对是否有效 */
    unsigned int identify_vip;
    int identify_id;    /* 比中的手指 */
    unsigned int begin; /* 开始按压时间 */

    /* Recovery */
    unsigned int recovery_mode;   /* 使能 Recovery */
    unsigned int recovery_lasttime;
    unsigned int recovery_stage;
    unsigned int recovery_id[2];
    unsigned int recovery_id_cnt;
    unsigned int recovery_cnt1;
    unsigned int recovery_cnt2;

    /* Verify timer */
    unsigned short identify_timer;
    unsigned char identify_lock;
    int identify_result;
    void (*task_run)(void);

    /* measure phase */
    int p1;
    int p2;
    int data;
    int phase;
    int phase_time;
    int lowpower_cnt;
    int phase_fingeroff;
    int phase_fingeroff_time;

    int taskrun_lock;
    unsigned short poweroff_timer_id;
};



struct fp_protocol_info* fp_info(void);

void protoEn(unsigned mode);
unsigned int isProtoEn(void);
void measure_lock(int identify_id);
void measure_phase(void);
int  measure_tryunlock(void);
void measure_unlock(void);
unsigned int measure_diff(void);

void notify(int p1, int p2, int data);

void taskrun_lock(void);
void taskrun_unlock(void);
int is_taskrun_lock(void);

void poweroff_timer_init(unsigned short poweroff_timer_id);
void update_poweroff_timer(void);

#endif /* __BTL_FINGERPRINT_API_H__ */

